package com.parking.util;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import com.parking.entity.Bounds;
import com.parking.entity.FreeParking;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.index.quadtree.Quadtree;

public class NearbyMatch {
	
	public static List<FreeParking> getFreeParkingByBounds(Bounds bounds, List<FreeParking> freeParkings){
		Point point = null;
		Envelope en = null;
		GeometryFactory geoFactory = new GeometryFactory();
		Quadtree tree = new Quadtree();
		Envelope envelope = new Envelope(bounds.getMaxLon(), bounds.getMaxLat(), bounds.getMinLon(), bounds.getMinLat());
		
		for (FreeParking freeParking : freeParkings) {
			point = geoFactory.createPoint(new Coordinate(Double.valueOf(freeParking.getLon()), Double.valueOf(freeParking.getLat())));
			en = point.getEnvelopeInternal();
			tree.insert(en, freeParking.getId());
		}
		
		List<Integer> ids = new LinkedList<Integer>();
		ids = tree.query(envelope);
		
		List<FreeParking> result = new ArrayList<FreeParking>();
		for (int id : ids) {
			
		}
		return null;
	}
}
